﻿#ifndef __GAF_LOG_H__
#define __GAF_LOG_H__

#define GAF_FILE			__FILE__
#define GAF_LINE			__LINE__
#define GAF_FUNCTION			__FUNCTION__
#define GAF_ENTER			"\n"
#define GAF_TAB				"\t"

#include "GAF_System.h"
#pragma WARNING(disable:4390)

#ifdef GAF_DEBUG
#define GAF_LOGTOFILE(_strFileName)	GAF::g_Log.ToFile(_strFileName)
#define GAF_CLOSELOGFILE(_nTemp)	GAF::g_Log.CloseFile()
#define GAF_MARK(_nTemp)		GAF::g_Log.ConsoleOut("", GAF::LOG_MARK, GAF_FILE, GAF_LINE, "")

#if defined(GAF_WIN32)
#define GAF_LOG(_str, ...)		GAF::g_Log.ConsoleOut(_str, GAF::LOG_LOG, GAF_FILE, GAF_LINE, __VA_ARGS__)
#define GAF_WARM(_str, ...)		GAF::g_Log.ConsoleOut(_str, GAF::LOG_WARM, "", 0, __VA_ARGS__)
#define GAF_NOTE(_str, ...)		GAF::g_Log.ConsoleOut(_str, GAF::LOG_NOTE, "", 0, __VA_ARGS__)
#define GAF_ERROR(_str, ...)		GAF::g_Log.ConsoleOut(_str, GAF::LOG_ERROR, GAF_FILE, GAF_LINE, __VA_ARGS__)
#elif defined(GAF_LINUX)
#define GAF_LOG(_str, ...)		GAF::g_Log.ConsoleOut(_str, GAF::LOG_LOG, GAF_FILE, GAF_LINE, __VA_ARGS__)
#define GAF_WARM(_str, ...)		GAF::g_Log.ConsoleOut(_str, GAF::LOG_WARM, "", 0, __VA_ARGS__)
#define GAF_NOTE(_str, ...)		GAF::g_Log.ConsoleOut(_str, GAF::LOG_NOTE, "", 0, __VA_ARGS__)
#define GAF_ERROR(_str, ...)		GAF::g_Log.ConsoleOut(_str, GAF::LOG_ERROR, GAF_FILE, GAF_LINE, __VA_ARGS__)
#endif

#else /*GAF_DEBUG*/
#define GAF_LOGTOFILE(_strFileName)
#define GAF_CLOSELOGFILE(_Temp)
#define GAF_MARK(_Temp)
#define GAF_LOG(_str, ...)
#define GAF_WARM(_str, ...)
#define GAF_NOTE(_str, ...)
#define GAF_ERROR(_str, ...)
#endif /*GAF_DEBUG*/

#define GAF_ERRMARK()			GAF_ERROR("", "")

#include "GAF_Define.h"

#ifdef GAF_DEBUG

namespace GAF
{
	class Log;
}
typedef GAF::Log			GAF_CLog;

namespace GAF
{
	/// 调试信息类型
	enum LogType
	{
		/// 标注，输出任意信息
		LOG_NOTE,
		/// 提示，输出信息，有换行，无位置
		LOG_WARM,
		/// 批注，输出信息，有换行，有位置
		LOG_LOG,
		/// 标记，只输出位置
		LOG_MARK,
		/// 错误，输出错误信息，有换行，有位置
		LOG_ERROR
	};
}
typedef GAF::LogType		GAF_ELogType;
#define GAF_LOG_NOTE		GAF::LOG_NOTE
#define GAF_LOG_WARM		GAF::LOG_WARM
#define GAF_LOG_LOG		GAF::LOG_LOG
#define GAF_LOG_MARK		GAF::LOG_MARK
#define GAF_LOG_ERROR		GAF::LOG_ERROR

namespace GAF
{
	/// 调试信息类
	class Log
	{
	public:
		Log();
		~Log();

		/// 控制台输出
		void		ConsoleOut(_STRING strText, LogType ltType, _STRING strFile, int nLine, ...);

		/// 输出到文件
		void		ToFile(_STRING strFileName);
		/// 关闭输出文件
		void		CloseFile();

	private:
		void		CreateMark(_STRING strFile, int nLine);
		void		WriteFile(_STRING strText);

	private:
		_STRING		m_strConsoleText;

		bool		m_isFile;
		std::ofstream	m_ofLogFile;
	};

	/// 全局调试信息实例
	extern Log g_Log;

}
#endif /*GAF_DEBUG*/

#endif
